package com.gxa.hualian.service.impl;

import com.gxa.hualian.exception.BusinessException;
import com.gxa.hualian.mapper.AdminMapper;
import com.gxa.hualian.pojo.Admin;
import com.gxa.hualian.service.AdminService;
import com.gxa.hualian.util.JsonResult;
import com.gxa.hualian.util.MD5Util;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Map;
import java.util.jar.JarEntry;

/**
 * @Author 杨天可
 * @Date 2020/10/22 18:24
 * @Version 1.0
 */
@Service("adminService")
public class AdminServiceImpl implements AdminService {

    @Resource
    AdminMapper adminMapper;

    @Override
    public Map login(String phone, String pwd) {
        if(phone.equals("") || pwd.equals("")){
            throw new BusinessException("用户名或密码不能为空");
        }

        JsonResult jsonResult = new JsonResult();
        Admin admin1 = adminMapper.selectByPrimaryKey(1);
        //处理接收的密码
        String pwd1 = MD5Util.encode(pwd);
        pwd1=MD5Util.encode(pwd1);
        //将客户端传过来的信息进行对比
        if (phone.equals(admin1.getName()) || pwd1.equals(admin1.getPwd())){
            jsonResult.setCode("200");
            jsonResult.setMsg("登录成功");
        }else {
            jsonResult.setCode("400");
            jsonResult.setMsg("用户名或密码错误");
        }
        return jsonResult.getValues();
    }
}
